
/*
 *
 * Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ClientExample.Client.Interface
{
    public partial class NotificationWindow : Form
    {
        protected delegate void DummyDelegate();
        protected Timer timer = new Timer();
        protected bool bShow = true;
        protected bool bMouseOver = false;

        public static int currentCount = 0;

        public string Title
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }

        public string Message
        {
            get { return label2.Text; }
            set { label2.Text = value; }
        }

        public NotificationWindow()
        {
            InitializeComponent();
            layoutWindow1.MouseEnter += new EventHandler(layoutWindow1_MouseEnter);
            label1.MouseEnter += new EventHandler(layoutWindow1_MouseEnter);
            label2.MouseEnter += new EventHandler(layoutWindow1_MouseEnter);

            layoutWindow1.MouseLeave += new EventHandler(layoutWindow1_MouseLeave);
            label1.MouseLeave += new EventHandler(layoutWindow1_MouseLeave);
            label2.MouseLeave += new EventHandler(layoutWindow1_MouseLeave);

            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 200;
            timer.Start();

            this.Opacity = 0.0;
        }

        void layoutWindow1_MouseLeave(object sender, EventArgs e)
        {
            bMouseOver = false;
        }

        void layoutWindow1_MouseEnter(object sender, EventArgs e)
        {
            bMouseOver = true;
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if (bMouseOver)
            {
                this.Opacity = 1;
                return;
            }
            if (bShow)
            {
                if (this.Opacity < 1)
                    this.Opacity += 0.05;
                else
                {
                    bShow = false;
                }
            }
            else
            {
                if (this.Opacity > 0)
                    this.Opacity -= 0.05;
                else
                {
                    timer.Stop();
                    Close();
                }
            }
        }

        public new void Show()
        {
            Screen currentScreen = Screen.PrimaryScreen;
            Point p = new Point(currentScreen.WorkingArea.Left + currentScreen.WorkingArea.Width - layoutWindow1.Width, currentScreen.WorkingArea.Bottom - (layoutWindow1.Height * ++currentCount));
            this.Bounds = new System.Drawing.Rectangle(p, layoutWindow1.Size);
            base.Show();
        }

        protected override void OnClosed(EventArgs e)
        {
            --currentCount;
            base.OnClosed(e);
        }
    }
}
